﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using GraphBase.Interfaces;
using ObjectGraph.Core;
using ObjectGraph.Core.Interfaces;


namespace GraphBase
{
    public class EdgeAction : GenericCollectionAction, IEdgeAction
    {
        IGraph m_graph;
        IEdge m_edge;
        IVertex m_from;
        IVertex m_to;

        public EdgeAction(Graph graph, Edge edge, Vertex from, Vertex to, ECollectionActionType actionType )
            : base(
                actionType
                , delegate()
                {
                    ((EdgeCollection)graph.Edges).zzAdd( edge, from, to );
                }
                , delegate()
                {
                    ((EdgeCollection)graph.Edges).zzRemove( edge, from, to );
                } )
        {
            m_graph = graph;
            m_edge = edge;
            m_from = from;
            m_to = to;
        }


        #region IEdgeAction Members

        public IEdge Edge
        {
            get { return m_edge; }
        }

        public IVertex Incoming
        {
            get { return m_from; }
        }

        public IVertex Outgoing
        {
            get { return m_to; }
        }

        #endregion

        #region IGraphAction Members

        public IGraph Graph
        {
            get { return m_graph; }
        }

        #endregion
    }

    public class VertexAction : GenericCollectionAction, IVertexAction
    {
        Vertex m_vertex;
        Graph m_graph;

        public VertexAction(Graph graph, Vertex vertex, ECollectionActionType actionType)
            : base ( actionType
                , delegate()
                {
                    ((VertexCollection)graph.Vertexes).zzAdd( vertex );
                }
                , delegate()
                {
                    ((VertexCollection)graph.Vertexes).zzRemove( vertex );
                } )
        {
            m_graph = graph;
            m_vertex = vertex;
        }

        #region IVertexAction Members

        public IVertex Vertex
        {
            get { return m_vertex; }
        }

        #endregion

        #region IGraphAction Members

        public IGraph Graph
        {
            get { return m_graph; }
        }

        #endregion
    }
}
